<template>
  <div class="smart-home">

    <!-- 面包屑 -->
    <el-card class="box-card box-card-bgcolor">
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/main/home' }">当前位置：首页</el-breadcrumb-item>
        <el-breadcrumb-item>平台管理</el-breadcrumb-item>
        <el-breadcrumb-item>平台通知发布</el-breadcrumb-item>
      </el-breadcrumb>
    </el-card>
    <!-- 待处理事项： -->
    <el-card class="box-card box-card-bgcolor">
      <div slot="header" class="clearfix">
        <i class="el-icon-edit-outline icon-home"></i>
        <span class="home-title-text blue">发布通知：</span>
      </div>
      <!-- <div class="text item"> -->
        <!-- <div class="pending-items"> -->
          <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="标题">
              <el-input v-model="form.title" name='username'></el-input>
            </el-form-item>
            <el-form-item label="内容">
              <el-input type="textarea" v-model="form.content" name="password"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">发布</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        <!-- </div> -->
      <!-- </div> -->
    </el-card>
  </div>
</template>

<script>
import {getCookie} from '../../assets/js/cookie'
import { get } from 'http';
export default {
   data() {
      return {
        form: {
          title:'',
          content:'',
          sender:''
        },
        username: '',
        password: ''
      }
    },
    methods: {
      onSubmit() {
        this.username = getCookie('userName')
        this.password = getCookie('password')

        var params1 = {
          username:this.username,
          password:this.password,
        }
        //通过调用该接口获得当前用户的id
        this.$http.get("http://localhost/server/php/selectSender.php",{params:params1}).then(res =>{
          console.log('res2',res)
          if (res.status == '200') {
            this.form.sender = res.data.id.id
          }
           var params2 = {
          title:this.form.title,
          content:this.form.content,
          sender:this.form.sender,
          date:this.getNowFormatDate()
        }
        //把添加好的信息传到数据库中
        this.$http.get("http://localhost/server/php/tableInset.php",{params:params2}).then(res =>{
        console.log('res3',res)
        if (res.status == '200') {
          this.$message.success(res.data.message)
        }
     })
      })
    },
    getNowFormatDate() {//获取当前时间
      var date = new Date();
      var seperator1 = "-";
      var seperator2 = ":";
      var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
      var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
      var currentdate = date.getFullYear() + seperator1  + month  + seperator1  + strDate
          + " "  + date.getHours()  + seperator2  + date.getMinutes()
          + seperator2 + date.getSeconds();
      return currentdate;
    }
  }
}
</script>

<style scoped lang="scss">
  @import '@/assets/css/addserver.scss'
</style>
